home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 32
/
Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso
/
Aminet
/
comm
/
tcp
/
hserv.lha
/
hserv
/
main
/
hconf.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-24
|
18KB
|
517 lines
/* hconf.rexx - hserv preferences editor */
signal on halt
signal on break_c
call start
call readArguments
call initGlobal
call openGUI
call setMenuList
call openMainWin
call setServer
if readConfig()~=0 then call status global.error
else call status "File" global.file "read"
call setMainGadgets
call handle
call closeGui
exit
/***************************************************************************/
error: procedure expose global. sigl
parse arg code
if RXWIZERR~="RXWIZERR" then string = GetRxWizString(1001)":" RXWIZERR || d2c(10)
else string=""
string= string || GetRxWizString(code) || d2c(10) || GetRxWizString(1002)":" SIGL-1
say string
exit
/**************************************************************************/
start: procedure expose global.
l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
if AddLibrary("rexxsupport.library","rxsocket.library","rxwiz.library")~=0 then exit
global.program="HservPrefs"
global.ver="10.1"
global.prg=ProgramName("NOEXT")
global.author="Alfonso Ranieri"
global.hotkey="rawkey ctrl alt h"
global.path=PathPart(ProgramName("FULL"))
global.surface=AddPart(global.path,global.prg".wizard")
global.catalog=global.prg".catalog"
global.selected=0
global.server=""
global.snapshot=0
return
/***************************************************************************/
readArguments: procedure expose global.
parm.1.value=""
if ~ReadArgs("FILE,PUBSCREEN/K,SERVER/K") then do
call PrintFault()
exit
end
if parm.2.flag then global.server=parm.2.value
if parm.0.flag then global.file=parm.0.value
else do
f="conf/hserv.conf"
if exists(f) then global.file=f
else global.file=""
end
global.screen=parm.1.value
return
/***************************************************************************/
initGlobal: procedure expose global.
global.HostName = ""
global.Port = 80
global.Pri = 0
global.Status = "OPENED"
global.DocumentDir = ""
global.DocumentIndex = ""
global.CgiDir = ""
global.TransferLog = "OFF"
global.TransferFile = ""
global.ErrorLog = "SYS"
global.ErrorFile = ""
global.Auth = ""
global.RejectedIP = ""
global.MimeFile = ""
global.KeepAlive = 1
global.KeepAliveTimeout = 50
global.Timeout = 300
global.HostNameLookups = "OFF"
global.Ident = "OFF"
global.OnlyAmigaClient = "OFF"
global.DefImage = "ON"
global.Admin = ""
global.Specials = ""
global.Handlers = ""
global.VirtualHosts = ""
global.Errors = ""
return
/***************************************************************************/
readConfig: procedure expose global.
if global.file="" then do
global.error="No config file found"
return 6
end
call status "Reading file" global.file "..."
lines=ParseConfig(global.file,"CONF")
if lines==-1 then do
global.error="Config file '"global.file"' not found"
return 5
end
err=0
do i=0 to lines-1 while err=0
opt=conf.i
arg=conf.i.value
argu=upper(arg)
select
when opt=="HOSTNAME" then global.HostName=arg
when opt=="PORT" then
if ~DataType(arg,"N") then err=2
else if arg<1 | arg>65535 then err=2
else global.Port=arg
when opt=="STATUS" then
if argu~="OPENED" & argu~= "PAUSED" & argu~= "CLOSED" then err=1
else global.Status=argu
when opt=="PRI" then
if ~DataType(arg,"N") then err=2
else if arg<-128 | arg>128 then err=2
else global.Pri=arg
when opt=="DOCUMENTDIR" then global.DocumentDir=arg
when opt=="DOCUMENTINDEX" then global.DocumentIndex=arg
when opt=="CGIDIR" then global.CgiDir=arg
when opt=="AUTH" then global.Auth=arg
when opt=="HOSTNAMELOOKUPS" then
if argu~="ON" & argu~= "OFF" then err=1
else global.HostNameLookups=argu
when opt=="ERRORLOG" then
if argu~="ON" & argu~= "OFF" & argu~="SYS" then err=1
else global.ErrorLog=argu
when opt=="ERRORFILE" then global.ErrorFile=arg
when opt=="TRANSFERLOG" then
if argu~="ON" & argu~= "OFF" & argu~="SYS" then err=1
else global.TransferLog=argu
when opt=="TRANSFERFILE" then global.TransferFile=arg
when opt=="IDENT" then
if argu~="ON" & argu~= "OFF" then err=1
else global.ident=argu
when opt=="KEEPALIVE" then
if ~DataType(arg,"N") then err=2
else global.KeepAlive=arg
when opt=="KEEPALIVETIMEOUT" then
if ~DataType(arg,"N") then err=2
else global.KeepAliveTimeout=arg
when opt=="TIMEOUT" then
if ~DataType(arg,"N") then err=2
else global.Timeout=arg
when opt=="REJECTEDIP" then global.RejectedIP=arg
when opt=="MIMEFILE" then global.MimeFile=arg
when opt=="ONLYAMIGACLIENT" then
if argu~="ON" & argu~= "OFF" then err=1
else global.OnlyAmigaClient=argu
when opt=="DEFIMAGE" then
if argu~="ON" & argu~= "OFF" then err=1
else global.DefImage=argu
when opt=="ADMIN" then global.admin=arg
when opt=="SPECIALS" then global.Specials=arg
when opt=="HANDLERS" then global.Handlers=arg
when opt=="VIRTUALHOSTS" then global.VirtualHosts=arg
when opt=="ERRORS" then global.Errors=arg
otherwise err=3
end
end
i=i-1
select
when err==1 then global.error="bad option '"arg"' in line" conf.i.line
when err==2 then global.error="bad number '"arg"' in line" conf.i.line
when err==3 then global.error="unknown option '"opt"' in line" conf.i.line
when err==4 then global.error="bad argument '"arg"' in line" conf.i.line
otherwise nop
end
if err~=0 then return err
if global.ErrorFile=="" & global.ErrorLog~="SYS" then global.ErrorLog="OFF"
if global.TransferFile=="" & global.TransferLog~="SYS" then global.TransferLog="OFF"
if global.RejectedIP~="" then global.HostNameLookups="ON"
return 0
/***************************************************************************/
openGUI: procedure expose global.
call SetStacks(,8192)
s.pubscreen=global.screen
s.fallback=1
s.catalog=global.catalog
s.AppName=global.prg
s.AppIcon=AddPart(global.path,global.prg)
s.CxTitle=global.program global.ver "©" global.author
s.CxDescr="hserv preferences editor"
s.MasterWin="MW"
s.AutoClose=1
res=OpenSurface(global.surface,"S")
if res~=0 then call error(res)
global.ss=SurfaceSignal("S")
mw.ID=1
mw.Gads=118
mw.nowindow=1
res=OpenWindow("S","MW")
if res~=0 then call error(res)
return
/***************************************************************************/
closeGui: procedure expose global.
call CloseWindow("S","MW")
if global.snapshot then call SnapShot("S")
return
/***************************************************************************/
setMenuList: procedure expose global.
list.0="Host";list.0.pen=1;list.0.spen=2
list.1="Conns";list.1.pen=1;list.1.spen=2
list.2="Docs";list.2.pen=1;list.2.spen=2
list.3="Config";list.3.pen=1;list.3.spen=2
list.4="Specials";list.4.pen=1;list.4.spen=2
list.5="Log";list.5.pen=1;list.5.spen=2
list.6="Flags";list.6.pen=1;list.6.spen=2
list.7="About";list.7.pen=1;list.7.spen=2
global.maxmenu=7
set.list="LIST"
set.selected=global.selected
call SetWizAttrs("S","MW","MENU","SET")
drop set.
set.page=global.selected
call SetWizAttrs("S","MW","PAGER","SET")
return
/***************************************************************************/
setMainGadgets: procedure expose global.
set.string=global.hostname
call SetWizAttrs("S","MW","HOSTNAME","SET")
set.string=global.admin
call SetWizAttrs("S","MW","ADMIN","SET")
set.string=global.specials
call SetWizAttrs("S","MW","SPECIALS","SET")
set.string=global.handlers
call SetWizAttrs("S","MW","HANDLERS","SET")
set.string=global.VirtualHosts
call SetWizAttrs("S","MW","VIRTUALHOSTS","SET")
set.string=global.Errors
call SetWizAttrs("S","MW","ERRORS","SET")
set.string=global.documentdir
call SetWizAttrs("S","MW","DOCUMENTDIR","SET")
set.string=global.cgidir
call SetWizAttrs("S","MW","CGIDIR","SET")
set.string=global.documentindex
call SetWizAttrs("S","MW","DOCUMENTINDEX","SET")
set.string=global.auth
call SetWizAttrs("S","MW","AUTH","SET")
set.string=global.rejectedip
call SetWizAttrs("S","MW","REJECTEDIP","SET")
set.string=global.mimefile
call SetWizAttrs("S","MW","MIMEFILE","SET")
set.string=global.transferfile
call SetWizAttrs("S","MW","TRANSFERFILE","SET")
set.string=global.errorfile
call SetWizAttrs("S","MW","ERRORFILE","SET")
set.string=global.documentdir
call SetWizAttrs("S","MW","DOCUMENTDIR","SET")
drop set.
set.integer=global.port
call SetWizAttrs("S","MW","PORT","SET")
set.integer=global.KeepAlive
call SetWizAttrs("S","MW","KEEPALIVE","SET")
set.integer=global.KeepAliveTimeout
call SetWizAttrs("S","MW","KEEPALIVETIMEOUT","SET")
set.integer=global.timeout
call SetWizAttrs("S","MW","TIMEOUT","SET")
set.integer=global.pri
call SetWizAttrs("S","MW","PRI","SET")
drop set.
w.OPENED=0;w.PAUSED=1;w.CLOSED=2
t=global.status
set.active=w.t
call SetWizAttrs("S","MW","STATUS","SET")
w.ON=0;w.OFF=1;w.SYS=2
t=global.transferlog
set.active=w.t
call SetWizAttrs("S","MW","TRANSFERLOG","SET")
e=global.errorlog
set.active=w.e
call SetWizAttrs("S","MW","ERRORLOG","SET")
drop set.
set.disabled=a>0
call SetWizAttrs("S","MW","TRANSFERFILE","SET")
call SetWizAttrs("S","MW","TRANSFERFILEPOP","SET")
set.disabled=b>0
call SetWizAttrs("S","MW","ERRORFILE","SET")
call SetWizAttrs("S","MW","ERRORFILEPOP","SET")
drop set.
set.checked=global.hostnamelookups="ON"
call SetWizAttrs("S","MW","HOSTNAMELOOKUPS","SET")
set.checked=global.ident="ON"
call SetWizAttrs("S","MW","IDENT","SET")
set.checked=global.onlyamigaclient="ON"
call SetWizAttrs("S","MW","ONLYAMIGACLIENT","SET")
set.checked=global.DefImage="ON"
call SetWizAttrs("S","MW","DEFIMAGE","SET")
return
/***************************************************************************/
handle: procedure expose global.
if global.server~="" then
call SetClip("HCONF_"global.server,pragma("ID"))
stop=0
ctrl_c=2**12
ctrl_d=2**13
ctrl_e=2**14
ctrl_f=2**15
global.signals=or(global.ss,ctrl_c,ctrl_d,ctrl_e,ctrl_f)
do while ~stop
mask=Wait(global.signals)
if and(mask,ctrl_c)~=0 then leave
if and(mask,ctrl_d)~=0 then call IconifySurface("S",1)
if and(mask,ctrl_e)~=0 then call IconifySurface("S",0)
if and(mask,ctrl_f)~=0 then call setServer
if and(mask,global.ss)~=0 then stop=handleGUI()
call setServer
end
if global.server~="" then do
call SetClip("HCONF_"global.server,"")
end
return
/**************************************************************************/
handleGUI: procedure expose global.
handle.wait=0
res=HandleSurface("S","HANDLE")
if res~=0 then call error(res)
do i=0 to handle.imsg-1
select
when handle.i.class="VANILLAKEY" then call GadgetKey("S",handle.i.window,handle.i.code,handle.i.qualifier)
when handle.i.class="RAWKEY" then do
shift=handle.i.qualifier~=32768
if handle.i.code=76 | handle.i.code=77 then do
if handle.i.code=77 & global.selected<global.maxmenu then
if shift then global.selected=global.maxmenu
else global.selected=global.selected+1
if handle.i.code=76 & global.selected>0 then
if shift then global.selected=0
else global.selected=global.selected-1
set.selected=global.selected
set.visible=set.selected
call SetWizAttrs("S","MW","MENU","SET")
drop set.;set.page=global.selected
call SetWizAttrs("S","MW","PAGER","SET")
end
end
when handle.i.class="MENUPICK" then do
select
when handle.i.objectID="MQUIT" then do
call CloseWindow("S",handle.i.window)
return 1
end
when handle.i.ObjectID="MHIDE" then call IconifySurface("S",1)
otherwise if handle.i.ObjectID~="" & handle.i.config~="" then interpret handle.i.config
end
end
when handle.i.class="IDCMPUPDATE" then do
select
when handle.i.ObjectID="CANCEL" then do
call CloseWindow("S",handle.i.window)
return 1
end
when handle.i.ObjectID="CLOSESERVER" then do
call sendServer("QUIT")
call CloseWindow("S",handle.i.window)
return 1
end
when handle.i.ObjectID="DOCUMENTINDEXPOP" then do
d=reqF(AddPart(global.documentdir,global.documentindex),0)
if d~="" then do
global.documentindex=FilePart(d)
set.string=global.documentindex
call SetWizAttrs("S","MW","DOCUMENTINDEX","SET")
end
end
otherwise if handle.i.ObjectID~="" & handle.i.config~="" then interpret handle.i.config
end
end
otherwise nop
end
end
return 0
/**************************************************************************/
reqF: procedure expose global.
parse arg f,onlyDrawer,save
f.SaveMode=save==1
f.window="S/MW"
if onlyDrawer then f.Drawer=f
else f.Drawer=PathPart(f)
f.File=FilePart(f)
f.DrawersOnly=onlyDrawer
if ReqFile("F")=0 then
if onlyDrawer then return f.drawer
else return addpart(f.drawer,f.file)
else return ""
/**************************************************************************/
status: procedure expose global.
parse arg msg
set.text=msg
call SetWizAttrs("S","MW","INFO","SET")
return
/**************************************************************************/
writeFile: PROCEDURE EXPOSE global.
parse arg file
call LockWindow("S","MW")
call status "Wrinting configuration..."
if ~open("OUT",file,"W") then do
call UnLockWindow("S","MW")
call status "Can't open file '"file"'"
return 0
end
conf="## hserv configuration file"d2c(10)"## created by" global.program"/"global.ver formatdate(,"%a, %d %b %Y %X")d2c(10)"##"d2c(10)
if global.HostName~="" then conf = conf || left("HostName",20) global.hostname || "A"x
if global.Admin~="" then conf = conf || left("Admin",20) global.Admin || "A"x
if global.Port~="" then conf = conf || Left("Port",20) global.Port || "A"x
if global.Pri~="" then conf = conf || Left("Pri",20) global.Pri || "A"x
if global.DocumentDir~="" then conf = conf || Left("DocumentDir",20) global.DocumentDir || "A"x
if global.DocumentIndex~="" then conf = conf || Left("DocumentIndex",20) global.DocumentIndex || "A"x
if global.CgiDir~="" then conf = conf || Left("CgiDir",20) global.CgiDir || "A"x
if global.RejectedIP~="" then conf = conf || Left("RejectedIP",20) global.RejectedIP || "A"x
if global.Auth~="" then conf = conf || Left("Auth",20) global.Auth || "A"x
if global.MimeFile~="" then conf = conf || Left("MimeFile",20) global.MimeFile || "A"x
if global.TransferLog~="" then conf = conf || Left("TransferLog",20) global.TransferLog || "A"x
if global.TransferFile~="" then conf = conf || Left("TransferFile",20) global.TransferFile || "A"x
if global.ErrorLog~="" then conf = conf || Left("ErrorLog",20) global.ErrorLog || "A"x
if global.ErrorFile~="" then conf = conf || Left("ErrorFile",20) global.ErrorFile || "A"x
if global.Status~="" then conf = conf || Left("Status",20) global.Status || "A"x
if global.KeepAlive~="" then conf = conf || Left("KeepAlive",20) global.KeepAlive || "A"x
if global.KeepAliveTimeout~="" then conf = conf || Left("KeepAliveTimeout",20) global.KeepAliveTimeout || "A"x
if global.Timeout~="" then conf = conf || Left("Timeout",20) global.Timeout || "A"x
if global.HostnameLookups~="" then conf = conf || Left("HostnameLookups",20) global.HostnameLookups || "A"x
if global.Ident~="" then conf = conf || Left("Ident",20) global.Ident || "A"x
if global.OnlyAmigaClient~="" then conf = conf || Left("OnlyAmigaClient",20) global.OnlyAmigaClient || "A"x
if global.DefImage~="" then conf = conf || Left("DefImage",20) global.DefImage || "A"x
if global.Special~="" then conf = conf || left("Specials",20) global.Specials || "A"x
if global.Handlers~="" then conf = conf || left("Handlers",20) global.Handlers || "A"x
if global.VirtualHosts~="" then conf = conf || left("VirtualHosts",20) global.VirtualHosts || "A"x
if global.Errors~="" then conf = conf || left("Errors",20) global.Errors || "A"x
if WriteCh("OUT",conf)~=length(conf) then call status "Error writing"
else call status "Configuration saved"
call close("OUT")
call UnLockWindow("S","MW")
return 1
/**************************************************************************/
dirReq: procedure expose global.
parse arg dir
interpret "d=reqF(global."dir",1)"
if d~="" then do
interpret "global."dir"=d"
set.string=d
call SetWizAttrs("S","MW",dir,"SET")
end
return
/**************************************************************************/
fileReq: procedure expose global.
parse arg file
interpret "d=reqF(global."file",0)"
if d~="" then do
interpret "global."file"=d;set.string=global."file
call SetWizAttrs("S","MW",file,"SET")
end
return
/**************************************************************************/
menuOpen: procedure expose global.
d=reqF(global.file,0)
if d="" then return
global.file=d
call initGlobal
res=readConfig()
call setMainGadgets
if res~=0 then call status global.error
else call status "File" global.file "read"
return
/**************************************************************************/
menuSaveAs: procedure expose global.
f=reqF(global.file,0,1)
if f="" then return
if writeFile(f) then do
global.file=f
call status "File" global.file "saved"
call sendServer("CONF" f)
end
return
/**************************************************************************/
menuRestore:procedure expose global.
call initGlobal
res=readConfig()
call setMainGadgets
if res~=0 then call status global.error
else call status "File" global.file "read"
return
/**************************************************************************/
openMainWin: procedure expose global.
mw.Title="HservPrefs ©" global.author
if global.server~="" then mw.Title=mw.Title "[for" global.server"]"
mw.MaxHeight=0
res=OpenWindow("S","MW")
if res~=0 then call error(res)
return
/**************************************************************************/
sendServer: procedure expose global.
parse arg msg
if show("P",global.server) then do
ADDRESS value(global.server)
msg
end
return
/**************************************************************************/
setServer: procedure expose global.
set.Page=show("P",global.server)
call SetWizAttrs("S","MW","CLOSESERVERPAGER","SET")
return
/**************************************************************************/
halt:
break_c:
exit
/**************************************************************************/
/*$VER: hconf.rexx 12.1 (14.5.99)*/